//
//  CZStatusTableViewCell.swift
//  WeiBO28
//
//  Created by 飞奔的羊 on 16/5/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit
/*
-原创微博视图
-转发微博视图
-底部 toolBar



*/

//首页微博 cell
//子控件之间的间距
let StatusTabkeViewCellNargin: CGFloat = 10
//首页微博字体带下
let HomeFontSize: CGFloat = 14
class CZStatusTableViewCell: UITableViewCell {

	var toolBarTop: Constraint?
	//  设置数据
	var statusViewModel: CZStatusViewModels? {
		didSet {
			originaView.statusViewModel = statusViewModel
			//卸载约束
			toolBarTop?.uninstall()
			if statusViewModel?.status?.retweeted_status != nil {
    
				//显示转发微博视图,绑定数据
				//给转发微博视图绑定数据
				retweetView.statusViewModel = statusViewModel
				retweetView.hidden = false
				toolBar.snp_updateConstraints(closure: { (make) in
					self.toolBarTop =  make.top.equalTo(retweetView.snp_bottom).constraint
				})
			} else {
			//更新约束,隐藏转发微博视频
				
			retweetView.hidden = true
			//更新约束
				toolBar.snp_updateConstraints(closure: { (make) in
				self.toolBarTop = make.top.equalTo(originaView.snp_bottom).constraint
					
				})
				
			}
			
	toolBar.statusViewModel = statusViewModel
//			print(statusViewModel?.status?.retweeted_status?.pic_urls)
			
		}
	}
	private lazy var originaView: CZStatusOriginalView = CZStatusOriginalView()
	//微博底部视图
	private lazy var toolBar: CZStatusTooBar = CZStatusTooBar()
	
//	var statusList: CZStatusViewModels?
	override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
		super.init(style: style, reuseIdentifier: reuseIdentifier)
		setUpUI()
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	
	private lazy var retweetView: CZStatusRetweetView = CZStatusRetweetView()
	private func setUpUI() {
	
		contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
	contentView.addSubview(toolBar)
//		
		contentView.addSubview(retweetView)
		contentView.addSubview(originaView)
		//设置约束
//		contentView.addSrubview(toolBar)
		originaView.snp_makeConstraints { (make) in
			make.top.equalTo(contentView).offset(8)
			make.leading.equalTo(contentView)
			make.trailing.equalTo(contentView)
//			make.height.equalTo(100)
			
		}
	
		toolBar.snp_makeConstraints { (make) in
			self.toolBarTop = make.top.equalTo(retweetView.snp_bottom).constraint
//			make.top.equalTo(retweetView.snp_bottom)
			make.leading.equalTo(contentView)
			make.trailing.equalTo(contentView)
			make.height.equalTo(40)
		}
//		contentView.backgroundColor = RandomColor()
		//关键约束,约束要健全
		contentView.snp_makeConstraints { (make) in
			make.bottom.equalTo(toolBar)
			make.leading.equalTo(self)
			make.trailing.equalTo(self)
			make.top.equalTo(self)
		}
		
		retweetView.snp_makeConstraints { (make) in
			make.top.equalTo(originaView.snp_bottom)
			make.leading.equalTo(contentView)
			make.trailing.equalTo(contentView)
		}
		
	}
	


}
